package dk.itu.spct;

import java.io.BufferedInputStream;
import java.io.DataOutputStream;
import java.io.File;
import java.io.FileInputStream;
import java.io.IOException;
import java.io.OutputStream;
import java.net.InetAddress;
import java.net.Socket;

public class SendImageTester {

	public static void main (String args[]) throws Exception{
		InetAddress serverAddress;
		try {
			serverAddress = InetAddress.getByName("10.27.249.193");
			int serverPort = 45678;
			Socket socket = new Socket(serverAddress, serverPort);
			
			File myFile = new File ("C:\\Users\\Jesper\\workspace\\mt4j-desktop_bak\\examples\\images\\Jesper Sandberg.jpg");
			byte [] mybytearray  = new byte [(int)myFile.length()];
			FileInputStream fis = new FileInputStream(myFile);
			BufferedInputStream bis = new BufferedInputStream(fis);
			bis.read(mybytearray,0,mybytearray.length);
		    
			OutputStream os = socket.getOutputStream();
			DataOutputStream dos = new DataOutputStream(os);
		    
	        dos.writeInt((int)myFile.length());
	        dos.write(mybytearray,0,mybytearray.length);
	        dos.flush();
        	dos.close();
		} catch (IOException e) {
			// TODO Auto-generated catch block
			e.printStackTrace();
		}
	}
}
